package com.sc.nft.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.sc.nft.dao.UserWorkRoomDao;
import com.sc.nft.entity.ApplicationRequirement;
import com.sc.nft.entity.UserInfo;
import com.sc.nft.entity.vo.ApplicationRequirementFactoryVO;
import com.sc.nft.enums.ApplicationRequirementEnum;
import com.sc.nft.service.ApplicationRequirementFactoryService;
import com.sc.nft.util.DecideUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import static com.sc.nft.enums.ApplicationRequirementEnum.TEAM_NURTURING_COMMUNITY;

/**
 * 团队社区网店
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class CommunityNetworkApplicationRequirementFactoryServiceImpl implements ApplicationRequirementFactoryService {


    private final UserWorkRoomDao userWorkRoomDao;

    @Override
    public ApplicationRequirementFactoryVO applicationRequirement(UserInfo userInfo, ApplicationRequirement applicationRequirement,Integer type) {
        Integer areIncludedInTheSpecifiedCollection = userWorkRoomDao.getsHowManyCommunityOutletsAreIncludedInTheSpecifiedCollection(userInfo.getId());
        ApplicationRequirementFactoryVO applicationRequirementFactoryVO = new ApplicationRequirementFactoryVO();
        applicationRequirementFactoryVO.setKey(StrUtil.format("{}{}{}", applicationRequirement.getType().getDescription(), applicationRequirement.getJudgingCriteria(), applicationRequirement.valueConvert()));
        applicationRequirementFactoryVO.setAskForValue(applicationRequirement.getValue());
        applicationRequirementFactoryVO.setApplicationRequirementEnum(TEAM_NURTURING_COMMUNITY);
        applicationRequirementFactoryVO.setPracticalValue(areIncludedInTheSpecifiedCollection);
        applicationRequirementFactoryVO.setPracticalValueStr(areIncludedInTheSpecifiedCollection);
        applicationRequirementFactoryVO.setSatisfy(DecideUtil.conditionalDecision(areIncludedInTheSpecifiedCollection, Convert.toInt(applicationRequirement.getValue()), applicationRequirement.getJudgingCriteria()));
        return applicationRequirementFactoryVO;
    }

    @Override
    public Integer code() {
        return TEAM_NURTURING_COMMUNITY.getCode();
    }

}
